package com.syj.collect.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.previewlibrary.GPreviewBuilder;
import com.syj.collect.app.R;
import com.syj.collect.entry.UriBean;
import com.syj.collect.http.ApiServise;
import com.syj.collect.model.MyPhontoActivity;
import com.syj.collect.utils.GlideUtils;
import com.syj.collect.utils.GsonUtil;

import java.util.ArrayList;
import java.util.List;

class PictureItemAdapter extends RecyclerView.Adapter<PictureItemAdapter.ItemViewHoder> {

    private List <String> data;
    private MyPhontoActivity con;
    public PictureItemAdapter(MyPhontoActivity context, List<String> urls) {
       this.data=urls;
       this.con=context;
    }

    @NonNull
    @Override
    public PictureItemAdapter.ItemViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_mypic,parent,false);
        return new ItemViewHoder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PictureItemAdapter.ItemViewHoder holder, int position) {
        GlideUtils.Image(holder.itm_img, ApiServise.BASEURLFILE+data.get(position));
        holder.itm_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                List<UriBean>  ben=new ArrayList<>();
                for (int i = 0; i <data.size() ; i++) {
                    ben.add(new UriBean(ApiServise.BASEURLFILE+data.get(i)));
                }
                GPreviewBuilder.from(con)
                        .setData(ben)
                        .setCurrentIndex(position)
                        .setSingleFling(true)//是否在黑屏区域点击返回
                        .setDrag(true)//是否禁用图片拖拽返回
                        .setType(GPreviewBuilder.IndicatorType.Number)//指示器类型
                        .start();

            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ItemViewHoder extends RecyclerView.ViewHolder {
        ImageView itm_img;
        public ItemViewHoder(@NonNull View itemView) {
            super(itemView);
            itm_img=itemView.findViewById(R.id.item_img);
        }
    }
}
